<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<%
String MAP_ID = "gmap_canvas";
String MAP_WIDTH = "380";
String MAP_HEIGHT = "300";

String DIR_ID = "gmap_directions";
String DIR_WIDTH = "380";

String INIT_MAP_LAT = "37.4419";
String INIT_MAP_LNG = "-122.1419";
String INIT_MAP_ALT = "10";

String ADDRESS_USER = (String)request.getAttribute("userAddress");
String ADDRESS_SOURCE_PHYSICAL = (String)request.getAttribute("sourcePhysicalAddress");
String MAP_ALT = "13";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
  <title>
  	<bean:message key="source.details.title"/>
  	<logic:present name="source">
  		<bean:write name="source" property="name" />
  	</logic:present>
  	<logic:notPresent name="source">
  		No source selected
 	</logic:notPresent>
  
  </title>
  <link rel="stylesheet" href="<%=request.getContextPath() %>/default.css" type="text/css">
  <html:base/>
  
  <logic:present name="sourcePhysicalAddress">
  <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAE_jfUCwh2Y4yAV0Xtdq2SxTwM0brOpm-All5BF6PoaKBxRWWERRVfkXZaCIv8zE8fBanjWgiD_MCVA"
      type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

	var map = null;
    var geocoder = null;
    var directionsPanel = null;
	var directions = null;

    function loadGMap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("<%=MAP_ID %>"));
        map.setCenter(new GLatLng(<%=INIT_MAP_LAT %>, <%=INIT_MAP_LNG %>), <%=INIT_MAP_ALT %>);
        //directionsPanel = document.getElementById("<%=DIR_ID %>");
        geocoder = new GClientGeocoder();
        showSourceAddress();
      }
    }
    
    function showUserAddress() {
    	showAddress("Your Location:", "<%=ADDRESS_USER %>");
   	}
   	
   	function showSourceAddress() {
    	showAddress("Book Source Location:", "<%=ADDRESS_SOURCE_PHYSICAL %>");
   	}
   	
   	function showAddress(name, address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, <%=MAP_ALT %>);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(name + "<br>" + address);
            }
          }
        );
      }
    }
    
    function showDirections() {
	  	//map.setCenter(new GLatLng(49.496675,-102.65625), 3);
	  	directions = new GDirections(map, directionsPanel);
	  	//directions.load(from + " to " + to);
	  	directions.load("<%=ADDRESS_USER %> to <%=ADDRESS_SOURCE_PHYSICAL %>");
	}
    
    //]]>
    </script>
    </logic:present>

</head>
<body onload="loadGMap()" onunload="GUnload()">
  
<div id="header">
	<div id="logo">
		<h1>
			<html:img width="40" src="../images/EMPTY.GIF"/>
			<html:link page="/pages/home.jsp">Textbook Crossroads</html:link>
		</h1>
		<h2>Team 14 - LoneTree</h2>
	</div>
	<div id="menu">
		<ul>
			<li>
			<logic:notPresent name="logged_in_user_in_session">
			<html:link page="/pages/home.jsp">Home</html:link>
			</logic:notPresent>
			<logic:present name="logged_in_user_in_session">
			<logic:equal value="false" name="logged_in_user_in_session" property="admin">
			<html:link action="/PrepForMyBooks">Dashboard</html:link>
			</logic:equal>
			<logic:equal value="true" name="logged_in_user_in_session" property="admin">
			<html:link page="/pages/admindashboard.jsp">Dashboard</html:link>
			</logic:equal>
			</logic:present>
			</li>
			<li class="active"><html:link page="/pages/books.jsp">Books</html:link></li>
			<li><html:link page="/pages/courses.jsp">Courses</html:link></li>
			<li><html:link page="/pages/about.jsp">About</html:link></li>
			<li class="logon">
			<logic:notPresent name="logged_in_user_in_session">
			<html:link page="/pages/logon.jsp">LogIn</html:link>
			</logic:notPresent>
			<logic:present name="logged_in_user_in_session">
			<html:link action="/logout">LogOut</html:link>
			</logic:present>
			</li>
		</ul>
	</div>
</div>

<div id="content">
  <div id="sidebar">
		<div id="categories">
			<div id="archives" class="boxed">
				<h2><html:link href="userdashboard.jsp">MyActions</html:link></h2>
				<div class="content">
					<ul>
			    		<li><html:link page="/PrepForMyBooks.do?manage=books">Manage MyBooks</html:link></li>
			            
			            <li><html:link page="/PrepForMyBooks.do?manage=sections">Manage MySections</html:link></li>
					</ul>
				</div>
			</div>
		</div>
		
	  <div id="categories">
			<div id="archives" class="boxed">
				<h2>buying</h2>
				<div class="content">
					<ul>
						<li>Options</li>
					
					<logic:present name="sourcePhysicalAddress">
						<li><span onclick="showUserAddress()" style="color: #0078FF; cursor: pointer">Display your location</span></li>
						<li><span onclick="showSourceAddress()" style="color: #0078FF; cursor: pointer">Display source location</span></li>
						<%-- <li><span onclick="showDirections()" style="color: #0078FF; cursor: pointer">Display you-to-source directions</span></li> --%>
					</logic:present>
					
					<logic:present name="sourceEmailAddress">
						<li><a href="mailto:<bean:write name="sourceEmailAddress" />" target="_blank">Send email to seller</a></li>
					</logic:present>
					
					<logic:present name="sourceElectronicAddress">
						<li><a href="<bean:write name="sourceElectronicAddress" />" target="_blank">Buy online</a></li>
					</logic:present>
					
					</ul>
				</div>
			</div>
		</div>
  </div>
  
  <div id="posts">
		<div class="post">
			<h2 class="title">Source Details</h2>
			
			<logic:notPresent name="source">
				<div class="meta">
					<p class="date">None:</p>
				</div>
				<div class="story">
					<p>No source has been selected. Please browse for books and select a source.</p>
				</div>
			</logic:notPresent>
			
			<logic:present name="source">
				<div class="meta">
					<p class="date">Vitals:</p>
				</div>
				<div class="story">
					<p>
					<strong>Book:</strong><br>
					<bean:write name="source" property="parentBook.title" />
					</p>
					<p>
					<strong>Seller:</strong><br>
					<bean:write name="sourceType" />: <bean:write name="source" property="name" />
					</p>
					<p>
					<strong>Price:</strong><br>
					$<bean:write name="source" property="price" />
					</p>
					<p>
					<strong>Description:</strong><br>
					<logic:present name="source" property="description">
						<bean:write name="source" property="description" />
					</logic:present>
					<logic:notPresent name="source" property="description">
						<i>None</i>
					</logic:notPresent>
					</p>
				</div>
				<logic:present name="sourcePhysicalAddress">
					<div class="meta">
						<p class="date">Location:</p>
					</div>
					<div class="story">
						<p><div id="<%=MAP_ID %>" style="width: <%=MAP_WIDTH %>px; height: <%=MAP_HEIGHT %>px; border: 1px solid black;"></div></p>
					</div>
					<%--
					<div class="meta">
						<p class="date">Directions:</p>
					</div>
					<div class="story">
						<p><div id="<%=DIR_ID %>" style="width: <%=DIR_WIDTH %>px;"></div></p>
					</div>
					--%>
				</logic:present>
			</logic:present>
		</div>
	</div>
  </div>
	  
  
<div id="footer">
	<p id="copy">&copy;2007 LoneTree.</p>
	<p> (Andrew Lee | Bojan Martin | Dimeji Omikunle | Minghui Yu)</p>
</div>
</body>
</html:html>
